package com.csp.app.client;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.csp.app.entity.Admin;
import com.csp.app.entity.Clasz;
import com.csp.app.entity.Course;
import com.csp.app.entity.Exam;
import com.csp.app.entity.ExamGroup;
import com.csp.app.entity.Score;
import com.csp.app.entity.Student;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@FeignClient(value = "PRODUCT-DATA-SERVICE",fallback = ServerHystrix.class)
public interface ServiceClient {
    @RequestMapping("/login")
    Admin login(Admin admin);

    /**
     * 查询所有
     *
     * @return
     */
    @RequestMapping("/searchAllClass")
    List<Clasz> searchAllClass();

    @RequestMapping("/selectClassList")
    List<Clasz> selectClassList(EntityWrapper<Clasz> wrapper);

    /**
     * 添加单条记录
     *
     * @param clasz
     * @return
     */
    @RequestMapping("/addClasz")
    boolean addClasz(Clasz clasz);

    /**
     * 批量添加班级
     *
     * @param claszs
     * @return
     */
    @RequestMapping("/batchAddClass")
    boolean batchAddClass(List<Clasz> claszs);

    /**
     * 查询所有课程
     *
     * @return
     */
    @RequestMapping("/searchAllCourse")
    List<Course> searchAllCourse();

    /**
     * 批量添加课程
     *
     * @param courses
     * @return
     */
    @RequestMapping("/batchAddCourse")
    boolean batchAddCourse(List<Course> courses);

    /**
     * 添加学生
     *
     * @param examGroup
     * @return
     */
    @RequestMapping("/addExamGroup")
    boolean addExamGroup(ExamGroup examGroup);

    @RequestMapping("/selectExamGroupCount")
    Integer selectExamGroupCount(EntityWrapper<ExamGroup> wrapper);

    @RequestMapping("/selectExamGroupPage")
    Page<ExamGroup> selectExamGroupPage(@RequestParam Page<ExamGroup> page,@RequestParam  EntityWrapper<ExamGroup> wrapper);

    /**
     * 批量添加学生
     *
     * @param examGroups
     * @return
     */
    @RequestMapping("/batchAddExamGroup")
    boolean batchAddExamGroup(List<ExamGroup> examGroups);


    /**
     * 查询所有考试组
     *
     * @return
     */
    @RequestMapping("/searchAllClass")
    List<ExamGroup> searchAllExamGroup();

    @RequestMapping("/searchAllExam")
    List<Exam> searchAllExam();

    @RequestMapping("/selecExamCout")
    Integer selecExamCout(EntityWrapper<Exam> wrapper);

    @RequestMapping("/selectExamPage")
    Page<Exam> selectExamPage(@RequestParam Page<Exam> page, @RequestParam EntityWrapper<Exam> wrapper);

    /**
     * 添加考试
     *
     * @param exam
     * @return
     */
    @RequestMapping("/addExam")
    boolean addExam(Exam exam);

    /**
     * 批量添加考试
     *
     * @param exams
     * @return
     */
    @RequestMapping("/batchAddExam")
    boolean batchAddExam(List<Exam> exams);

    /**
     * 通过考试组查询考试
     *
     * @param groupId
     * @return
     */
    @RequestMapping("/getExamsByGroupId")
    List<Exam> getExamsByGroupId(Integer groupId);

    /**
     * 添加成绩记录
     *
     * @param score
     * @return
     */
    @RequestMapping("/addScore")
    boolean addScore(Score score);

    /**
     * 批量录入成绩
     *
     * @param scores
     * @return
     */
    @RequestMapping("/batchAddScore")
    boolean batchAddScore(List<Score> scores);


    /**
     * 个人成绩单
     *
     * @param student
     * @param examGroupId
     * @param page
     * @param limit
     * @param orderField
     * @param orderType
     * @return
     */
    @RequestMapping("/getPersonScores")
    Page getPersonScores(@RequestParam Student student, @RequestParam Integer examGroupId, @RequestParam Integer page, @RequestParam Integer limit, @RequestParam String orderField, @RequestParam String orderType);

    /**
     * 查询年级成绩总览
     *
     * @param examGroupId
     * @return
     */
    @RequestMapping("/getGradeScore")
    JSONArray getGradeScore(Integer examGroupId);


    /**
     * 查询班级某课程平均分
     *
     * @param examId
     * @return
     */
    @RequestMapping("/selectCourseScoreAvgByExamId")
    List<Map> selectCourseScoreAvgByExamId(Integer examId);

    /**
     * 查询班级某课程总分
     *
     * @param examId
     * @return
     */
    @RequestMapping("/selectCourseScoreTotalByExamId")
    List<Map> selectCourseScoreTotalByExamId(Integer examId);


    /**
     * 查询班级课程平均分排名
     *
     * @param examId
     * @return
     */
    @RequestMapping("/searchCourseScoreAvgOrderMap")
    Map<String, Map> searchCourseScoreAvgOrderMap(Integer examId);

    /**
     * 查询班级课程总分
     *
     * @param examId
     * @return
     */
    @RequestMapping("/searchCourseScoreTotalMap")
    Map searchCourseScoreTotalMap(Integer examId);

    /**
     * 查询年级总分排名
     *
     * @param examGroupId
     * @return
     */
    @RequestMapping("/searchTotalScoreGradeOrderMap")
    Map<Object, Integer> searchTotalScoreGradeOrderMap(Integer examGroupId);

    /**
     * 查询班级总分排名
     *
     * @param examGroupId
     * @param classId
     * @return
     */
    @RequestMapping("/searchTotalScoreClassOrderMap")
    Map<Object, Integer> searchTotalScoreClassOrderMap(@RequestParam Integer examGroupId, @RequestParam Integer classId);

    /**
     * 查询某学生某场考试对应的分数
     *
     * @param studentId
     * @param examId
     * @return
     */
    @RequestMapping("/getScoreByStudentAndExamId")
    Score getScoreByStudentAndExamId(@RequestParam Long studentId, @RequestParam Integer examId);

    /**
     * 查询单科班级排名
     *
     * @param examId
     * @param classId
     * @return
     */
    @RequestMapping("/getClassScoreOrderMap")
    Map<Object, Integer> getClassScoreOrderMap(@RequestParam Integer examId, @RequestParam Integer classId);

    /**
     * 查询单个年级排名
     *
     * @param examId
     * @return
     */
    @RequestMapping("/getGradeScoreOrderMap")
    Map<Object, Integer> getGradeScoreOrderMap(Integer examId);

    /**
     * 查询班级成绩单
     *
     * @param classId
     * @param examGroupId
     * @return
     */
    @RequestMapping("/getClassScore")
    JSONObject getClassScore(@RequestParam Integer classId, @RequestParam Integer examGroupId);

    /**
     * 构建前端展示分数信息的模板
     *
     * @param examGroupId
     * @return
     */
    @RequestMapping("/getScoreShowTemplate")
    JSONArray getScoreShowTemplate(Integer examGroupId);

    /**
     * 分析班级或年级某课程分数段分布情况
     *
     * @param examGroupId
     * @param classId
     * @param courseId
     * @param minScore
     * @param maxScore
     * @param granularity
     * @return
     */
    @RequestMapping("/analyzeCourseScoreScale")
    List analyzeCourseScoreScale(@RequestParam Integer examGroupId, @RequestParam Integer classId, @RequestParam Integer courseId, @RequestParam Integer minScore
            , @RequestParam Integer maxScore, @RequestParam Integer granularity);

    @RequestMapping("/analyzeTotalScoreScale")
    List analyzeTotalScoreScale(@RequestParam Integer examGroupId, @RequestParam Integer classId, @RequestParam Integer minScore
            , @RequestParam Integer maxScore, @RequestParam Integer granularity);

    /**
     * 添加学生
     *
     * @param student
     * @return
     */
    @RequestMapping("/addStudent")
    boolean addStudent(Student student);


    /**
     * 批量添加学生
     *
     * @param students
     * @return
     */
    @RequestMapping("/batchAddStudent")
    boolean batchAddStudent(List<Student> students);

    /**
     * 查询那些学生参加了对应的考试
     *
     * @param examGroupId
     * @return
     */
    @RequestMapping("/selectStudentsByExamGroupId")
    List<Object> selectStudentsByExamGroupId(Integer examGroupId);

    /**
     * 分页查询
     *
     * @param student
     * @param page
     * @param limit
     * @param studentName
     * @param orderFiled
     * @param orderType
     * @return
     */
    @RequestMapping("/searchStudentSelectivePage")
    Page<Student> searchStudentSelectivePage(Student student, @RequestParam Integer page, @RequestParam Integer limit, @RequestParam String studentName
            , @RequestParam String orderFiled, @RequestParam String orderType);

    @RequestMapping("/getExamFromCacheByKey")
    Exam getExamFromCacheByKey(String key);

    @RequestMapping("/getCourseFromCacheByKey")
    Course getCourseFromCacheByKey(String key);

    @RequestMapping("/getScoreCount")
    Integer getScoreCount(EntityWrapper<Score> wrapper);

    @RequestMapping("/updateScoreById")
    boolean updateScoreById(Score score);

    @RequestMapping("/selectScorePage")
    Page<Score> selectScorePage(@RequestParam Page<Score> page, @RequestParam EntityWrapper<Score> wrapper);

    @RequestMapping("/selectScoreList")
    List<Score> selectScoreList(EntityWrapper<Score> wrapper);

    @RequestMapping("/selectCourseList")
    List<Course> selectCourseList(EntityWrapper<Course> wrapper);

    @RequestMapping("/insertCourse")
    boolean insertCourse(Course course);

}
